package com.wenhai.leetcode.search;

/**
 *https://leetcode-cn.com/problems/binary-search/
 *
 * @author wenhai
 * @date   2021/3/2
 */
public class _704二分查找 {
    public int search(int[] nums, int target) {
        int res = search(nums, 0, nums.length - 1, target);
        System.gc();
        return res;
    }

    private int search(int[] e, int l, int r, int target) {
        if (l > r) {
            return -1;
        }

        int mid = l + ((r - l) >>> 1);
        if (e[mid] == target) {
            return mid;
        }

        if (e[mid] > target) {
            return search(e, l, mid - 1, target);
        }

        return search(e, mid + 1, r, target);
    }
}
